<?php
namespace App\Exports;

use Maatwebsite\Excel\Concerns\FromArray;

class ExampleExport implements FromArray
{
    protected $exampleData;

    public function __construct(array $exampleData)
    {
        $this->exampleData = $this->formatOrders($exampleData);
    }

    /**
     * 格式化导出数据
     *
     * @param array $exampleData
     * @return void
     * @param
     * @author liangl
     */
    private function formatOrders(array $exampleData)
    {
        //导出的数据
        $exportData[] = [
            '学号',
            '姓名',
            '分数'
        ];

        if ($exampleData) {
            foreach ($exampleData as $key => $value) {
                $exportData[] = [
                    $value['no'],
                    $value['name'],
                    $value['score']
                ];
            }
        }

        return $exportData;
    }

    public function array(): array
    {
        return $this->exampleData;
    }

}